<template>
  <cube-cascade-picker :data="addressData" :show="show" @cancel="close()" @select="selectAddress"></cube-cascade-picker>
</template>
<script>
  import cubeCascadePicker from './cubeCascadePicker.vue'
  export default {
    components: {cubeCascadePicker},
    props: {
      show: {
        type: Boolean,
        default: false
      }
    },
    data () {
      return {
        addressData: [],
        selectData: {}
      }
    },
    created () {
      this.getArea()
    },
    methods: {
      getArea () {
        const self = this
        this.$api.fill.getArea().then(res => {
          if (res.code === 0) {
            self.province = res.data
            self.province.forEach(function (province, i) {
              delete province.shopNum
              province.children.forEach(function (city, i) {
                delete city.shopNum
                city.children.forEach(function (county, i) {
                  delete county.shopNum
                  delete county.children
                })
              })
            }, this)
            self.addressData = self.province
          }
        })
      },
      selectAddress (data) {
        const self = this
        self.selectData = data
        this.$emit('select', self.selectData)
      },
      close () {
        this.$emit('cancel')
      }
    }
  }
</script>
<style>
</style>